const useDebounce = (fn: (...args: any[]) => any, delay = 500) => {
  let timer: any = null; // 标识符
  const run = (...a: any[]) => {
    // 有就清除
    if (timer != null) {
      clearTimeout(timer);
      timer = null;
    }
    timer = setTimeout(() => {
      fn(...a);
      timer = null;
    }, delay);
  };
  run.clearTime = () => {
    clearTimeout(timer);
    timer = null;
  };
  return run;
};

export default useDebounce;
